/**
 * @author Syang4
 */

var MarketIdx_Util={
	formatNumber:function(n){
		var zs = ['000', '00', '0'];
	    var ar=[],t,p1= Math.floor(n),ret;
	    do {
            t = p1 % 1000;
            p1 = Math.floor(p1 / 1000);
            st = '' + t;
            if (p1 > 0 && st.length < 3) {
                st = zs[st.length] + st
            }
            ar.push(st);
        }while (p1 > 0);
        ret = '' + ar.pop();
        while (ar.length > 0) {
            ret += ("," + ar.pop())
        };
		return ret;
	}
};
var QS_MarketIdx = function(callback){
    this.containerId = null;
    this.container = null;
    this.id = null;
    this.profile = {
        chartCfg:{days:1},
		hasSetting:true
    };
    this.callback=callback||{};
    this.tabMenu = null;
    this.dataGrid = null;
    this.activeRow = null;
    this.miniChartDom = null;
    this.miniChartHeight = 180;
    this.miniChart = null;
    this.lastSubscribeTicker = null;
    this.menuContex = [{id: 1,txt: 'Canada',closable: false},{id: 2,txt: 'U.S.',closable: false},{id: 3,txt: 'Morningstar',closable: false},{id: 4,txt: 'Asian',closable: false},{id: 5,txt: 'European',closable: false}];
	this.gridData = {
        1:['0P00008IVF','0P00008PAC', '0P00001QO6','0P00001FJG','0P00001G7J', '0P00001G7B', '0P00001GJH', '0P00001GJK'],//American
        
//		1:['0P00008IVF','0P00008PAC', '0P00001QO6'],//Canada
        2:['0P00001FJG','0P00001G7J', '0P00001G7B', '0P00001GJH', '0P00001GJK'],//US
        3:['0P00001GJH','0P00001GJI', '0P00001GJJ', '0P00001GJK'],              //Morningstar
        4:['0P00006NNM','0P00006MR4', '0P00001FL8', '0P00001G5J', '0P00001MUH'],//Asian
        5:['0P00001IS1','0P00008ICX', '0P00006G3M', '0P00006F1A', '0P00006NOT']//European
    };
    this.symbolsList = {
//       1:{'0P00008IVF':'S&P/TSX Comp','0P00008PAC':'S&P/TSX 60', '0P00001QO6':'S&P/TSX Venture'},//Canada
        1:{'0P00008IVF':'S&P/TSX Comp','0P00008PAC':'S&P/TSX 60', '0P00001QO6':'S&P/TSX Venture','0P00001FJG':'DJIA','0P00001G7J':'S&P 500 ', '0P00001G7B':'NASDAQ', '0P00001GJH':'Morningstar U.S. Market', '0P00001GJK':'Morningstar Small Cap'},//American
//        1:{'0P00008IVF':'S&P/TSX Comp','0P00008PAC':'S&P/TSX 60', '0P00001QO6':'S&P/TSX Venture'},//Canada
       2:{'0P00001FJG':'DJIA','0P00001G7J':'S&P 500 ', '0P00001G7B':'NASDAQ', '0P00001GJH':'Morningstar U.S. Market', '0P00001GJK':'Morningstar Small Cap'},//US
		3:{'0P00001GJH':'US Market','0P00001GJI':'Large Cap', '0P00001GJJ':'Mid Cap', '0P00001GJK':'Small Cap'},              //Morningstar
        4:{'0P00006NNM':'Shanghai', '0P00006MR4':'Nikkei225', '0P00001FL8':'Hang Seng', '0P00001G5J':'Bombay', '0P00001MUH':'Australia'},//Asian
        5:{'0P00001IS1':'FTSE 100','0P00008ICX':'CAC 40','0P00006G3M':'DAX Frankfurt', '0P00006F1A':'AEX Amstrdm', '0P00006NOT':'SMI Zurich'}//European
    };
	this.timezone={
		'0P00001FJG':"CT",
		'0P00001G7J':"CT",
		'0P00001G7B':"CT",
		'0P00001GJH':"CT",
		'0P00001GJK':"CT",
		'0P00001GJI':"CT",
		'0P00001GJJ':"CT",
		'0P00001GJK':"CT",
		'0P00006NNM':"CST",
		'0P00006MR4':"JST",
		'0P00001FL8':"CST",
		'0P00001G5J':"IST",
		'0P00001MUH':"EDT",
		'0P00001IS1':"GMT",
		'0P00008ICX':"CET",
		'0P00006G3M':"CET",
		'0P00006F1A':"CET",
		'0P00006NOT':"CET"
	};
    this.gKeyList = {1:[],2:[],3:[],4:[],5:[]};//{1:[],2:[],3:[],4:[],5:[]};
    this.chart = null;
    this.HTML = '<div class="qs-marketindex">'+
                    '<div class="tabmenu"></div>'+
                    '<div class="grid"></div>'+
                    '<div class="minichart" style="visibility:hidden;"></div>'+
                '</div>';
    
    this.tValidation = new tickerValidation(17);
    this.tValidation.needFilterSecurityType = false;
    
    this.chartScopeDdl = null;
    this.lastCallbackHeight=null;
    this.minWidth=120;
    this.loaded=false;
    this.rowHeight=19;
    this.count=0;
};
QS_MarketIdx.prototype = {
    init: function(ContainerId, Profile, Sid){
        var self = this;
        this.containerId = ContainerId;
        this.container = $('#' + ContainerId);
        this.id = Sid;
       $.extend(this.profile, Profile);
        this.el = $(this.HTML);
        this.el.appendTo(this.container);
        if(this.profile.width){
            this.el.find(".grid").css({
                width: this.profile.width
            });
        }
		
		if(this.profile.chartHeight){
			this.miniChartHeight = this.profile.chartHeight;
		}
		
		if(this.__winObj && this.profile.height){
			this.profile.height -= 26;
		}
        this.initMenu();
		this.scrollPanel = new Util.ScrollPanel(this.el.find(".grid"),{showX:false});
		if(this.profile.hasSetting){
			this.createSettingPannel();
		}
    },
    initMenu: function(){
        var self = this;
        var cb = {
            onActive: function(tab){
                if(self.currentTabMenuId != tab.id){
                    self.currentTabMenuId = tab.id;
                    self.activeRow = null;
                    if (!self.dataGrid) {
                        self.initGrid();
                    }else if(self.profile.chartFixed != "true"){
                        self.el.find(".minichart").css({"visibility":"hidden"}).appendTo(self.el);
                    }
                    self.reBuildGridData(tab.id);
                }
            }
        };
        this.tabMenu = new Util.TabMenu(this.el.find(".tabmenu"), this.menuContex, cb, {
            autoResize:true,
			tabsList: false,
            vertical: false
        });
    },
    initGrid: function(){
        var self = this;
		
		var columnMap = {
			name:{header: '',dataIndex: 'Symbol',dataType: 'string',width: "30%", per:28}, 
			date:{header: 'Date',dataIndex: 'Date',align: 'right',dataType: 'Date',dataFormat: 'yyyy-M-d',className: 'bold-cell',width: "18%", per:18}, 
			chg:{header: 'Chg',dataIndex: 'Chg',align: 'right',dataType: 'float',className: 'bold-cell',width: "15%", per:14}, 
			perchg:{header: 'Chg%',dataIndex: 'Chg%',align: 'right',dataType: 'float',className: 'bold-cell',width: "15%", per:15}, 
			lastprice:{header: 'Last',dataIndex: 'LastPrice',align: 'right',dataType: 'float',width: "15%", per:18},
			updown: {header: '<span style="display:none;">Up/Down</span>',dataIndex: 'UpDown',width: '5%',className: 'column-updown',align: 'center', per:5}
		}
		
		var cols = this.profile.column||"name,date,lastPrice,perChg,chg";
			cols = cols.split(',');
        var column = [{header: 'id',dataIndex: 'id',dataType: 'string',hide: true,width: "0"},
						{header: 'id',dataIndex: 'id',dataType: 'string',hide: true,width: "0"}];
        
		var perSum = 0;
		for (var index = 0, length = cols.length; index < length; index++) {
			var col = cols[index].toLowerCase();
			if(columnMap[col]){
				perSum += columnMap[col]["per"];
				column.push(columnMap[col]);
			}
		}
		
		for (var i = 0; i < column.length; i++) {
			column[i]["width"] = column[i]["per"] / perSum * 100 + "%";
		}
		
        var self=this;
        var cb = {
            onRowSelected: function(e, row){
                var gkey = row.id;//self.gKeyList[self.currentTabMenuId]["gKeyList"][0];
                if (self.activeRow !== row) {
                    if (typeof(self.activeRow) != "undefined" && self.activeRow != null) { // wrap the old row.
                        self.activeRow.cells["Symbol"].el.css({"font-weight":"normal"});
                        self.activeRow.cells["Symbol"].el.find('.rtq-grid-cell-ctn').css({'white-space':'nowrap', 'word-break':'keep-all'});
                        self.activeRow.cells["LastPrice"].el.css({"font-weight":"normal"});
                        
						if (self.profile.chartFixed != "true") {
							self.activeRow.el.animate({height: self.rowHeight+'px'}, {
	                            duration: "normal",
	                            complete: function(){
	                                self._animateComplete()
	                            }
	                        });
						}
                    }else{
                        self.count++;
                    }
					
					if (self.profile.chartFixed != "true") {
						row.el.animate({
	                        height: (self.miniChartHeight+ self.rowHeight)+ 'px'
	                    }, {
	                        duration: "normal",
	                        complete:function(){
                                self._animateComplete();
                            }
	                    });
					}else{
						self._animateComplete();
					}
                    
                    self.activeRow = row;
                    self.activeRow.cells["Symbol"].el.css({"font-weight":"bold"});
                    self.activeRow.cells["Symbol"].el.find('.rtq-grid-cell-ctn').css({'word-break':'keep-all', 'white-space':'nowrap'});
                    self.activeRow.cells["LastPrice"].el.css({"font-weight":"bold"});
                    self.drawMiniChart(row, gkey,function(data){
                        //alert("draw mini chart callback");
                        self.el.find(".minichart").css("visibility","visible")
                        self._animateComplete();
						if(self.profile.showTime){
                            var time = self._getLastTimefromData(data);
							var timezone = "";
							if(self.activeRow&&self.activeRow.data&&self.activeRow.data.id){
								if(gData&&gData[self.activeRow.data.id]&&gData[self.activeRow.data.id]["performanceId"]){
									var tid = gData[self.activeRow.data.id]["performanceId"];
									if(self.timezone&&self.timezone[tid]){
										timezone =self.timezone[tid];
									}
								}
							}
							self.el.find('.rtc-legend-txt .time').html(time+" "+timezone);
                        }
                        //self._changeOutSize(self.profile.width,self.profile.height);
                    });
                }
				
				var legend = self.el.find('.rtc-legend-txt .ticker');
				if (legend.length > 0) {
					var name = row.cells.Symbol.text;
					legend.html(name);
				}
            }
        };
        this.dataGrid = new Util.DataGrid(this.el.find(".grid"), [], {
			column: column,
			//width: "100%",
			autoWidth: true,
			//height: 80,
			autoHeight: true,
			headerRow: this.profile.headerRow != "true" ? false : true,
			htmlLayer: 'div',
			// rowDragable: true,
			// rowDropable: true,
			rowDragDropGroup: 'GRID1'
		}, cb);
		if(this.profile.headerRow == "true"){
			this.el.find(".grid .rtq-grid-hd").css({"display":"block"});
		}
    },
    _animateComplete:function(){
        this.count++;
        if(this.count==3){
            this.count=0;
            this._changeOutSize(this.profile.width,this.profile.height);
        }
    },
	_pp0:function (n){
        if (n < 10) 
            n = '0' + n;
        return n;
    },
    _getLastTimefromData:function(d){
        var l = d.length-1,tick=0,time="";
        for(var i=l;i>=0;i--){
            if(!isNaN(d[i][1])){
                tick = d[i][d[i].length-1];
                break;
            }
        }
        if(tick>0){
            var dt = new Date(tick);
            time = this._pp0(dt.getHours())+":"+this._pp0(dt.getMinutes());
        }
		return time;
    },
    createSettingPannel: function(){
        var  self = this;
        var settingPN = this.__winObj.settingPanelObj.settingPN;
		settingPN.addClass('rtq-window-setpn-mki');
        var settingPNGroupBox = new Util.GroupBox(settingPN.find(".wrap"), [{
            name: 'Display',
            id: 1
        }], {
            width: 177,
            groupBoxHeight: 150
        });     
        settingPNGroupBox.getGroup(1).bd.html('<h5>Chart Scope</h5>');
        
        this.chartScopeDdl = new Util.DropDownList(settingPNGroupBox.getGroup(1).bd, function(t, v){
	            self.profile.chartRange = v;
	            self.changChartRange(v);
        	}, [{txt: '1 Day',val: '1d' }, 
				{txt: '5 Days',val: '5d' },
				{txt: '1 Month',val: '1m'}, 
				{txt: '3 Months',val: '3m'}, 
				{txt: '6 Months',val: '6m'}, 
				{txt: '1 Year',val: '1y'}, 
				{txt: '2 Years',val: '2y'}], 
		 	{width: 163,className:"rtq-ddl-black"}
		 );
    },
    changChartRange:function(r){
        var self=this;
        var l = r.length - 1, step = parseInt(r.substr(0,l));
        var today = new Date(), todayIdx = RTQ_ChartUtil.toDateIndex(today);
        var cfg = {"endIndex":todayIdx}; 
        switch (r.charAt(l)) {
            case "d":
                cfg["freq"] = 1;
                cfg["startIndex"] = todayIdx - (step - 1);
                cfg["days"] = step;
                break;
            case "m":
                var y = today.getFullYear(), m = today.getMonth();
                if (m > step - 1) {
                    m = m - step;
                }
                else {
                    y -= 1;
                    m = m + 12 - step;
                }
                var startDate = new Date(y, m, today.getDate());
                cfg["startIndex"] = RTQ_ChartUtil.toDateIndex(startDate);
                
                if (todayIdx - cfg["startIndex"] >= 60) {
                    cfg["freq"] = "d";
                }else{
                    cfg["freq"] = 30;
                }
                break;
            case "y":
                cfg["freq"] = "d";
                var y = today.getFullYear() - step, m = today.getMonth(),d = today.getDate();
                var startDate = new Date(y, m, d);
                cfg["startIndex"] = RTQ_ChartUtil.toDateIndex(startDate);
                break;
            default:
                break;
        }
        
        
        this.profile.chartCfg = cfg||{};
        if(this.miniChart&&this.activeRow){
            var gkey = this.activeRow.id;
            this.drawMiniChart(this.activeRow, gkey,function(data){
                self.el.find(".minichart").css("visibility","visible");
				if(self.profile.showTime){
                    var time = self._getLastTimefromData(data);
                    self.el.find('.rtc-legend-txt .time').html(time);
                }
            });
        }
    },
    drawMiniChart:function(row, gkey,callback){
        if(this.profile.chartFixed != "true")
			row.el.append(this.el.find(".minichart").css("visibility","hidden"));  // hide the old chart
        if(!this.miniChart){
            this.initMiniChart(gkey,callback);
        }else{
            this.miniChart.unSubscribe(this.lastSubscribeTicker,this.lastSubscribeTicker);
            this.subscribeTicker(gkey,callback);
        }
    },
    _isNull: function(d, fixPoint, needColor){
        var ret = '';
        if (typeof(d) == 'undefined' || !d) {
            ret = "";
        }
        else 
            if (needColor) {
                ret = fixPoint ? d.toFixed(fixPoint) : d;
            }
            else {
                var c = (d >= 0 ? QS_Style.greenFontColor : QS_Style.redFontColor);
                ret = fixPoint ? "<div style='color:"+c+"'>"+d.toFixed(fixPoint)+"</div>" : "<div style='color"+c+"'>"+d+"</div>";
            }
//          console.log(ret);
        return ret; 
    },
    _fillDList: function(gKeyList){
        var data = [];
        for (var i = 0; i < gKeyList.length; i++) {
            var d = {};
            d["id"] = gKeyList[i];
            
            d["Symbol"] = this.symbolsList[this.currentTabMenuId][gData[gKeyList[i]]["performanceId"]] ;
            //this._isNull(gData[gKeyList[i]]["ticker"]);
            d["Date"] = gData[gKeyList[i]]["TradeDate"]||''
            d["LastPrice"] = this._isNull(gData[gKeyList[i]]["LastPrice"],2);
            d["Chg"] = this._isNull(gData[gKeyList[i]]["Chg"],2);
            d["Chg%"] = this._isNull(gData[gKeyList[i]]["Chg%"],2);
            data.push(d);
        }
        return data;
    },
    initMiniChart: function(gkey, callback){
		this.miniChart = new minichart(this.el.find(".minichart"), $.extend(this.profile.chartProfile ||
		{
			lineType: "montain",
			showX: true,
			showY: true
		}, {
			width: this.profile["width"],
			height: this.miniChartHeight
		}));
		/**		
	 //		var a = {
	 //			width: this.profile["width"],
	 //			height: this.miniChartHeight,
	 //			lineWidth: 2,
	 //			lineType: "montain",
	 //			showX: false,
	 //			showY: false,
	 //			showYScaleNumber: true,
	 //			showYScale: false,
	 //			color: {
	 //				line: "#69789a"
	 //			}
	 //		};
	 //
	 //		var b = {
	 //			width: this.profile["width"],
	 //			height: this.miniChartHeight,
	 //			lineType: "montain",
	 //			showX: true,
	 //			showY: true
	 }
	 */
		this.subscribeTicker(gkey, callback);
	},
    subscribeTicker: function(gkey,callback){
        var self = this;
        var pid = gData[gkey]["secId"] || gData[gkey]["performanceId"];
        if(typeof this.showLoading =='function'){
			this.showLoading();
		}
        this.tValidation.checkTickers(pid, function(o){
            self.lastSubscribeTicker = o[0];
            self.miniChart.subscribe(o[0], o[0],self.profile.chartCfg||{days:1},function(data){
                if(typeof self.hideLoading=='function'){
					self.hideLoading();
				}
                if (typeof callback == 'function') {
                    callback(data);
                }
            });
        });
    },
    changeMinChartSize:function(w,h){  // cal miniChart Size.
        //var l = this.gKeyList[this.currentTabMenuId]["gKeyList"].length;
        this.miniChartHeight =180;//this.profile["height"]- 20*l - 28;
        this.el.find(".miniChart").css({width:w,height:h});
        if (this.miniChart) {
            this.miniChart.changeOutSize(w, h);
            //this.miniChart.changeOutSize(this.profile.width, this.miniChartHeight);
        }
    },
    reBuildGridData: function(id){
        if (typeof(this.gKeyList[id]["gKeyList"]) == 'undefined' || this.gKeyList[id]["gKeyList"].length == 0) {
            var ls = this.gridData[id];
            if(typeof this.showLoading =='function'){
				this.showLoading();
			}
            var self = this;
            this.tValidation.checkTickers(ls, function(gKeyList){
				if(typeof self.hideLoading=='function'){
					self.hideLoading();
				}
                self.gKeyList[id]["gKeyList"] = gKeyList;
                var gKeyMap = {};
                for (var i = 0; i < gKeyList.length; i++) {
                    gKeyMap[gKeyList[i]] = i;
                }
                self.gKeyList[id]["gKeyMap"] = gKeyMap;
                
                var data = self._fillDList(gKeyList)
                self.dataGrid.reBindData(data);
                for (var i = 0; i < gKeyList.length; i++) {
                    self.forceUpdateData(gKeyList[i], id);
                }
                if (data.length > 0) {
                    self.dataGrid.selectRow(data[0]["id"]);
                }
            });
        }
        else {
            var gKeyList = this.gKeyList[id]["gKeyList"], data = this._fillDList(gKeyList);
            this.dataGrid.reBindData(data);
            for (var i = 0; i < gKeyList.length; i++) {
                this.forceUpdateData(gKeyList[i], id);
            }
            if(data.length>0){
                this.dataGrid.selectRow(data[0]["id"]);
            }
        }
    },
    forceUpdateData: function(gKey, id){
        var aData = {};
        var cols = this.dataGrid.getColumnCfg(), field;
        for (var c in cols) {
            field = cols[c].dataIndex;
            if (field == "Up/Down") 
                field = "Chg";
            aData[field] = {
                dataType: cols[c].dataType,
                value: gData[gKey] == null ? null : push.proxy.getMarketQuoteData(gKey, field).value
            };
        }
        this.updateData(gKey, aData, false, id);
    },
    updateData: function(gKey, aData, needFlash, currentId){
        if (this.gKeyList[this.currentTabMenuId]["gKeyMap"]&&this.gKeyList[this.currentTabMenuId]["gKeyMap"].hasOwnProperty(gKey)) {
            var _flashMethod = needFlash === false ? (function(){}) : flash;
            for (var field in aData) {
                var type = aData[field].dataType;
                var gValue = aData[field].value;
                var oldData = aData[field].oValue;
                
                var data = gValue;
                var el = this.dataGrid.DOMMap[gKey][field];
				
                switch (field) {
                    case 'LastPrice':
                        typeof(el) == "undefined" ? null:_flashMethod(el, data, oldData);
                        var securitytype = gData[gKey]["type"];
                        data = formatDoubledata(data, securitytype);
						if(this.profile.decimal === false){
						  data = MarketIdx_Util.formatNumber(Math.round(data));
						}			
                        break;
                    case "Date":
                       data =  gData[gKey]["TradeDate"]||'';
                       break;
                    case 'Chg':
                    case 'Chg%':
						if (needFlash !== false && typeof(el) != "undefined") {
							flashWithDirectional(el, data, oldData, data >= 0);
						}else if(typeof(el) != "undefined"){
							el.style.color = (data >= 0 ? QS_Style.greenFontColor : QS_Style.redFontColor);
						}
                        
                        var securitytype = gData[gKey]["type"];
						if(this.profile.decimal === false&&field=="Chg")
                            data = formatDoubledata(data, securitytype,0);
						else if(this.profile.decimal === false&&field=="Chg%")
                            data = formatDoubledata(data, securitytype,1);
						else 
						    data = formatDoubledata(data, securitytype);
						if (field == "Chg%") { // update the up/down column;
	                        var upd = data;
	                        if (upd == 0 || typeof upd == 'undefined') {
	                            upd = '';
	                        }else {
	                            var cls = upd > 0 ? "up" : "down";
	                            upd = '<a class="updown ' + cls + '" href="javascript:void(0)">' + cls + '</a>';
	                        }
	                        var upEl = this.dataGrid.DOMMap[gKey]["UpDown"];
	                        if (upEl) 
	                            upEl.innerHTML = upd;
                    	}
                        break;
                    default:
                        break;
                }
                if(field == 'Chg%'&&/^[-\+]?\d+(\.\d+)?$/.exec(data) && this.profile.percentage !== false){
                    data = data + "%";
                }
                if (el && field != 'Symbol' && data != "NaN") {
                    el['innerHTML'] = data;
                }               
            }
        }
    },
    fileMenuCallback: function(v){
        if (v == "refresh") {
            //this.refreshIframe();
        }
    },
    _changeOutSize: function(w, h){
		//alert("change size"+w+":"+h);
		w = w > 0 ? w : this.container.width();
		h = h > 0 ? h : this.container.height();
		if (w < this.minWidth) {
			w = this.minWidth;
		}
		//this.profile.width=w;
		var size = {width: w};
		if (this.profile.fixHeight) {size.height = h;}
		$.extend(this.profile, {height: h, width: w});
		this.el.css(size);
		if (this.profile.fixHeight !== false && this.profile.chartFixed != "true") {
			var t = w;
			this.scrollPanel.reSize(w, h - 28);
			var self = this;
			window.setTimeout(function(){
				if (self.scrollPanel.scrollbarY.isShow) {
					t = t - 13;
				}
				self.changeMinChartSize(t, self.miniChartHeight);
				self.dataGrid.resize(t, null);
			}, 100);
		}
		else {
			this.dataGrid.resize(w, null);
		}
		var height = this.el.height();
		this.onHeightChange(height);
	},
    changeOutSize: function(w, h){
		this._changeOutSize(w,h);
		
//      w = w>0?w:this.container.width();
//      h = h>0?h:this.container.height();
//      if(w<this.minWidth){
//          w=this.minWidth;
//      }
//      var size={width:w};
//      if(this.profile.fixHeight){
//          size.height=h;
//      }
//		
//		this.profile.height = h;
//		this.profile.width = w;
//		
//      this.changeMinChartSize(w, this.miniChartHeight);
//  	this.el.css({height:h,width:w})
//      this.dataGrid.resize(w, this.profile.fixHeight?(h - 28):null);
//		//this.dataGrid.resize(w, h-28);
//		//this.scrollPanel.reSize(w, h-28);
//		var height=this.el.height();
//      this.onHeightChange(height);
    },
    onHeightChange:function(height){
        if (!this.loaded) {
            this.lastCallbackHeight = height;
            if (typeof this.callback.onLoad == 'function') {
                this.loaded = true;
                this.callback.onLoad({
                    component: 'marketIndex',
                    height: height,
                    minWidth:this.minWidth
                });
            }
        }else {
            if (this.lastCallbackHeight != height) {
                this.lastCallbackHeight = height;
                if (typeof this.callback.onHeightChange == 'function') {
                    this.callback.onHeightChange({
                        height: this.lastCallbackHeight,
                        component: 'marketIndex'
                    });
                }
            }
        }
    }
};
